#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
#include <sstream>
#include <memory>


//Jsoncpp 用来对数据进行序列化和反序列化的库
int main()
{
    // 反序列化
    std::string serize = "{\"name\":\"hdp\",\"age\":21,\"city\":\"赣州\"}";

    Json::Value root;
    Json::Reader reader;

    bool can = reader.parse(serize, root);
    (void)can;

    //反系列化到Json::Value里面,后提取出来
    std::string name = root["name"].asString();
    int age = root["age"].asInt();
    std::string city = root["city"].asString();

    std::cout << name << std::endl;
    std::cout << age << std::endl;
    std::cout << city << std::endl;

    // Json::Value root;
    // root["name"] = "hdp";
    // root["sex"] = "男";
    // root["age"] = "21";
    // Json::StreamWriterBuilder ss;
    // std::unique_ptr<Json::StreamWriter> write(ss.newStreamWriter());
    // std::stringstream s;
    // write->write(root, &s);
    // std::string s1 = s.str();
    // std::cout << s1 << std::endl;
    return 0;
}